package cn.iocoder.yudao.module.system.controller.admin.mini.orderInfo.order.controller.admin.order.vo;

import cn.iocoder.yudao.module.system.controller.admin.mini.orderInfo.order.dal.dataobject.order.OrderDO;
import lombok.*;

import java.time.format.DateTimeFormatter;
import java.time.LocalDateTime;
import java.math.BigDecimal;

import com.alibaba.excel.annotation.ExcelProperty;

/**
 * 小程序-订单 Excel VO
 *
 * @author 芋道源码
 */
@Data
public class OrderExcelVO {

    @ExcelProperty("订单号")
    private String orderCode;
    @ExcelProperty("商品名称")
    private String goodName;
    @ExcelProperty("商品ID")
    private Integer goodId;
    @ExcelProperty("订单状态")// 1: '代付款', 2:'待发货' ,3: '待收货' ,4: '已完成' ,5:'退款售后'
    private String orderStatus;
    @ExcelProperty("支付状态")//1已支付2未支付
    private String payStatus;
    @ExcelProperty("收货信息")
    private String address;
    @ExcelProperty("创建时间")
    private String createTime;
    @ExcelProperty("支付时间")
    private String payTime;
    @ExcelProperty("最新发货时间")
    private String logisticTime;
    @ExcelProperty("收货确认时间")
    private String confirmTime;
    @ExcelProperty("订单原价")
    private BigDecimal totalAmount;
    @ExcelProperty("商品成交价")
    private BigDecimal goodsAmount;
    @ExcelProperty("运费")
    private BigDecimal freightPrice;
    @ExcelProperty("会员折扣")
    private BigDecimal deduction;
    @ExcelProperty("付款金额")
    private BigDecimal payPrice;
    @ExcelProperty("供应商")
    private String supName;
    @ExcelProperty("代金券金额")
    private String balancePrice;

//    @ExcelProperty("下单时间")
//    private String addTime;


//    @ExcelProperty("用户手机号")
//    private String phone;


    public OrderExcelVO() {
    }

    public OrderExcelVO(OrderDO dto, String goodName, String supName, Integer goodsId) {
        this.createTime = trunTime(dto.getCreateTime());
        this.orderCode = dto.getOrderCode();
        this.goodId = goodsId;
        String orderStatus = "";
        switch (dto.getOrderStatus()) {
            case 1:
                orderStatus = "代付款";
                break;
            case 2:
                orderStatus = "待发货";
                break;
            case 3:
                orderStatus = "待收货";
                break;
            case 4:
                orderStatus = "已完成";
                break;
            case 5:
                orderStatus = "退款售后";
                break;
            case 6:
                orderStatus = "已失效";
                break;
        }
        this.orderStatus = orderStatus;

        String payStatus = "未支付";
        if (dto.getPayStatus() == 1) {
            payStatus = "已支付";
        }
        this.payStatus = payStatus;
        this.payTime = trunTime(dto.getPayTime());
        this.logisticTime = trunTime(dto.getLogisticTime());
        this.confirmTime = trunTime(dto.getConfirmTime());
//        this.addTime = trunTime(dto.getAddTime());
        this.totalAmount = dto.getTotalAmount();
        this.deduction = dto.getDeduction();
//        this.phone = dto.getPhone();
        this.goodsAmount = dto.getGoodsAmount();
        this.freightPrice = dto.getFreightPrice();
        this.payPrice = dto.getPayPrice();
        this.goodName = goodName;
        this.supName = supName;

        String address="";
        if (dto.getAddress()!=null){
            JslUserAddress userAddress = dto.getAddress();
            String aa="收货地址:"+userAddress.getProvinceName()+userAddress.getCityName()+userAddress.getDistrictName()+userAddress.getAddress();
            String bb="姓名:"+userAddress.getName();
            String cc="手机号:"+userAddress.getPhone();
            address=aa+"|"+bb+"|"+cc;
        }
        this.address=address;
        this.balancePrice=dto.getBalancePrice().toString();
    }

    public static String trunTime(LocalDateTime time) {
        if (time == null)
            return "";
        return time.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
    }
}
